﻿using System.Windows.Controls;
using System.Windows.Threading;
using Infrastructure.Controls;
using Infrastructure.ViewModels;
using Microsoft.Practices.Composite.Events;

namespace DocumentCommentModule.Views
{
    /// <summary>
    /// Interaction logic for DocumentCommentView.xaml
    /// </summary>
    public partial class DocumentCommentView : UserControl, IDocumentCommentView
    {
        readonly IEventAggregator _eventAggregator;
        Dispatcher dispatcher;


        /// <summary>
        /// Gets the <see cref="T:System.Windows.Threading.Dispatcher"/> this <see cref="T:System.Windows.Threading.DispatcherObject"/> is associated with.
        /// </summary>
        /// <value></value>
        /// <returns>The dispatcher.</returns>
        public Dispatcher Dispatcher
        {
            get
            {
                return dispatcher;
            }
        }

        /// <summary>
        /// Gets or sets the comment text.
        /// </summary>
        /// <value>The document.</value>
        public string Document
        {
            get
            {
                return CommentEditor.Document;
            }
            set
            {
                CommentEditor.Document = value;
            }
        }

        /// <summary>
        /// Gets the editor.
        /// </summary>
        /// <value>The editor.</value>
        public RtfEditor Editor
        {
            get
            {
                return CommentEditor;
            }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="DocumentCommentView"/> class.
        /// </summary>
        /// <param name="eventAggregator">The event aggregator.</param>
        public DocumentCommentView(IEventAggregator eventAggregator)
        {
            InitializeComponent();

            dispatcher = Dispatcher.CurrentDispatcher;
            _eventAggregator = eventAggregator;
        }

        /// <summary>
        /// Gets or sets the model.
        /// </summary>
        /// <value>The model.</value>
        public CatalogItemViewModel Model
        {
            get
            {
                return DataContext as CatalogItemViewModel;
            }
            set
            {
                DataContext = value;
                CommentEditor.Model = value;
            }
        }
    }
}
